# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        Young  
# Name:         demo6.04
# Description:
# Author:       $赵怡蕾
# Date:         2019/2/15
#-------------------------------------------------------------------------------

# 定义一个字典
dict = {"name":"Bill","age":34,"sex":"男","salary":"3456"}

# 迭代字典的key，运行结果：name = Bill age = 34 sex = 男 salary = 3456
for key in dict:
    print(key,"=",dict[key],end = " ")

print()
# 迭代字典的key和value
# 运行结果：name = Bill age = 34 sex = 男 salary = 3456
for key,value in dict.items():
    print(key,"=",value,end = " ")
print();
# 并行迭代
list1 = [1,2,3,4,5]
list2 = ["a","b","c","d","e"]
# 同时迭代list1和list2
for i in range(len(list1)):
    print("list1[" + str(i) + "]","=",list1[i],"list2[" +str(i) + "]","=",list2[i],end=" ")

print()
# 压缩迭代
# 运行结果：(1, 'a') (2, 'b') (3, 'c') (4, 'd') (5, 'e')
for value in zip(list1,list2):
    print(value,end = " ")
print()
list3 = ['x','y']
# 压缩迭代，两个参与压缩的列表中元素个数不同，以元素个数少的为准
# 运行结果：('a', 'x') ('b', 'y')
for value in zip(list2,list3):
    print(value,end = " ")

# 反转排序迭代
print()
values1 = [4,1,3,6,5,2,8]
# 对calues1进行排序，运行结果：[1, 2, 3, 4, 5, 6, 8]
print(sorted(values1))
# 对列表values1进行反转，运行结果：8 2 5 6 3 1 4
values2 = reversed(values1)
for v in values2:
    print(v,end=" ")
print()
# 反转"hello world"，运行结果：dlrow olleh
print(''.join(list(reversed("hello world"))))